<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="common_include :: commonHead('字典类型添加')"/>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <form class="form-horizontal m" id="form-dict-add">
                <div class="form-group">
                    <label class="col-sm-3 control-label">字典类型</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" id="dictType" name="dictType" readonly="true" th:value="${dictType}">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">代码</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="codeValue" id="codeValue">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label ">名称</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="codeText" id="codeText"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label ">描述</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="codeComment" id="codeComment"/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">样式属性</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" id="cssStyle" name="cssStyle">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">回显样式</label>
                    <div class="col-sm-8">
                        <select name="listStyle" class="form-control m-b">
                            <option value=""       >---请选择---</option>
                            <option value="default">默认</option>
                            <option value="primary">主要</option>
                            <option value="success">成功</option>
                            <option value="info"   >信息</option>
                            <option value="warning">警告</option>
                            <option value="danger" >危险</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">系统默认</label>
                    <div class="col-sm-8" th:with="dicts=${@dictCode.selectDictCodeByType('sys_yes_no')}">
                        <div th:each="dict : ${dicts}" th:class="${dict['cssStyle']}">
                            <input type="radio" th:id="${dict['codeValue']}" name="isDefault" th:value="${dict['codeValue']}"
                                   th:checked="${dict['isDefault'] == 'Y' ? true : false}">
                            <label th:for="${dict['codeValue']}" th:text="${dict['codeText']}"></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">字典排序</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="number" name="sortNumber">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态</label>
                    <div class="col-sm-8" th:with="dicts=${@dictCode.selectDictCodeByType('sys_normal_disable')}">
                        <div th:each="dict : ${dicts}" th:class="${dict['cssStyle']}">
                            <input type="radio" th:id="${dict['codeValue']}" name="codeStatus" th:value="${dict['codeValue']}"
                                   th:checked="${dict['isDefault'] == 'Y' ? true : false}">
                            <label th:for="${dict['codeValue']}" th:text="${dict['codeText']}"></label>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">模块名称</label>
                    <div class="col-sm-8">
                        <input class="form-control" type="text" name="moduleName">
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div th:include="common_include :: commonFoot"/>
<script type="text/javascript">
    var prefix = ctx + "system/dict/code"

    $("#form-dict-add").validate({
        rules:{
            codeValue:{
                required:true,
                remote: {
                    url: prefix + "/checkDictCodeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        codeValue: function () {
                            return $.trim($("#codeValue").val());
                        },
                        dictType: function() {
                            return $.trim($("#dictType").val());
                        }
                    },
                    dataFilter: function (data, value) {
                        return data == "0";
                    }
                }
            },
            codeText:{
                required:true,
            },
            sortNumber:{
                required:true,
                digits:true
            },
        },
        messages: {
            "codeValue": {
                remote: "该字典代码已经存在"
            }
        },
        submitHandler:function(form){
            $.operate.save(prefix + "/add", $('#form-dict-add').serialize());
        }
    });

    function submitClick() {
        if ($('#form-dict-add').valid()) {
            $('#form-dict-add').submit()
        }
    }
</script>
</body>
</html>
